hal_flash_write.c File Reference

Utility functions for writing to the MSP430 internal flash memory. More...

#include "hal.h"
#include "hal_flash_write.h"

Functions

signed int getSegmentSize (unsigned int segment)
signed int printInformationMemorySegment (unsigned int segment)
void printInformationMemory ()
signed char informationMemorySegmentIsErased (unsigned int segment)
signed int eraseInformationMemorySegment (unsigned int segment)
signed int save (unsigned int segment, unsigned int offset, char data)
void printResetReason ()
__ramfunc signed int writeFlashSegment (unsigned int segment, char *dataToWrite, unsigned int numBytes)

Variables

unsigned long mclk
unsigned long smclk

Detailed Description

Utility functions for writing to the MSP430 internal flash memory.

MSP430 Flash memory is divided into program memory & information memory.

Program Memory: Program memory must be erased in segments, but programmed in blocks. On the MSP430F2xx each segment is 512B and each block is 64B. MSP430F248 Program Flash from 0xFFFF to 0x4000 (48kB) in 512B segments, each divided into eight 64B blocks MSP430F247 Program Flash from 0xFFFF to 0x8000 (32kB) " " MSP430F2410 Program Flash from 0xFFFF to 0x2100 (56kB) " " Maximum address is 0xFFC0, higher than that is interrupt vectors.

Information Memory Information memory must be erased/programmed in segments. On the MSP430, Information Memory is from 0x10FF to 0x1000 (256B) in 64B segments Flash clock, fFTG must be from 257kHz to 476 kHz according to msp430F248 Datasheet, p69. Information Memory Segment A contains calibration data and shouldn't be touched. The state of the LOCKA bit is toggled when a 1 is written to it. Writing a 0 to LOCKA has no effect. This allows existing flash programming routines to be used unchanged.

Rev
708
Author
dsmith
Date
2010-08-12 18:07:37 -0700 (Thu, 12 Aug 2010)

Function Documentation

signed int eraseInformationMemorySegment ( unsigned int  segment  ) 

Erases a segment of information memory. Does not allow erasing segment A.

Parameters:
segment which information memory segment
Precondition:
SMCLK = 4000000
signed int getSegmentSize ( unsigned int  segment  ) 

Private helper function to get the size of info mem or prog mem segments

Returns:
the size of the memory segment, or -1 if not a defined memory segment
signed char informationMemorySegmentIsErased ( unsigned int  segment  ) 

Determines if a segment of flash is erased (all 0xFF)

Returns:
1 if it is erased, 0 if not, negative number if error
void printInformationMemory (  ) 

Displays the contents of all four information memory segments

signed int printInformationMemorySegment ( unsigned int  segment  ) 

Displays the contents of an information memory segment, with labels every 0x10 bytes

Parameters:
segment which information memory segment, either one of the predefined information memory segments or program memory segments
Returns:
-1 if error, 0 if success
signed int save ( unsigned int  segment,
unsigned int  offset,
char  data 
)

Writes a single byte to information memory.

Precondition:
this segment was erased
Returns:
0 if success, else an error
__ramfunc signed int writeFlashSegment ( unsigned int  segment,
char *  dataToWrite,
unsigned int  numBytes 
)

Writes sequential bytes to flash memory. Supports writing to info memory or program memory.

Parameters:
segment which flash memory segment to write to. Must be a predefined info mem segment (INFO_MEM_SEGMENT_B, INFO_MEM_SEGMENT_C, or INFO_MEM_SEGMENT_D) or prog mem segment
dataToWrite the data to write to flash
numBytes the numberOfBytes to write. Must be less than segment size: 64B for info mem or 512B for prog mem.
Precondition:
the desired segment(s) were erased
Returns:
0 if success; else an error code
Note:
the last segment of program flash, PROGRAM_MEMORY_LIMIT, must be defined
__ramfunc is an IAR intrinsic function. Using __ramfunc requires the following modifications for IAR 4.21. Add these in Project Options : Linker : Command Line Options. Newer versions may not need this. -Z(DATA)CODE_I=1100-20FF -QCODE_I=CODE_ID -Z(CODE)CODE_ID=4000-FFFF

Variable Documentation

unsigned long mclk

For total code + CONST size of 29k, (as of 1/28/10) flash up to 0x5669 is in use. time for segment erase = 4819/fFTG, or about 12mSec time for block program is about 1.73mSec per Block, so total per segment is approx. 15mSec. If writing entire 30kB firmware image (60segments) then total time is ~900mSec. Total time spent programming each block must be less than 4mSec. (i.e. don't include much stuff inbetween writing bytes)

 All Files Functions Variables
Generated on Thu Aug 19 11:48:31 2010 for Hardware Abstraction Layer by  doxygen 1.6.3